package com.cloud.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.common.entity.GoodsEntity;
import com.cloud.common.entity.GoodsKuEntity;
import com.cloud.stock.dao.GoodsKuDao;
import com.cloud.stock.service.GoodsKuService;
import com.cloud.stock.util.PageUtils;
import com.cloud.stock.util.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("goodsKuService")
public class GoodsKuServiceImpl extends ServiceImpl<GoodsKuDao, GoodsKuEntity> implements GoodsKuService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<GoodsKuEntity> queryWrapper = new QueryWrapper();

        String key = (String) params.get("key");
        if (StringUtils.isNoneEmpty(key)) {
            queryWrapper.and((obj) -> {
                obj.eq("goods_id", key).or().eq("id", key);
            });
        }

        IPage<GoodsKuEntity> page = this.page(
                new Query<GoodsKuEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}